package com.jk.bgmainconsumer.controller;

import com.jk.bgmainconsumer.entity.SlideShowEntity;
import com.jk.bgmainconsumer.service.SlideShowService;
import com.jk.bgmainconsumer.utils.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @描述
 * @参数 $
 * @返回值 $
 * @创建人 lgf
 * @创建时间 $
 * @修改人和其它信息
 */
@RestController
@RequestMapping("gyc")
public class SlideShowController {
    @Autowired
    private SlideShowService slideShowService;

    //查询正常的图 轮播图
    @RequestMapping("getList")
    public Object getList(){
        return slideShowService.getList();
    }

    //轮播图操作 逻辑删
    @RequestMapping("upShowStatus")
    public  void upShowStatus(Integer slideshowId){
        slideShowService.upShowStatus(slideshowId);
    }

    //回收站 查询不正常的图
    @RequestMapping("getList2")
    public Object getList2(){
        return slideShowService.getList2();
    }

    //回收站的恢复按钮 id为 slideshowId
    @RequestMapping("upstatus")
    public void upstatus(Integer slideshowId){
        slideShowService.upstatus(slideshowId);
    }

    //新增 正常 且下架的图
    @RequestMapping("addShow")
    public Object addShow(SlideShowEntity show){

        return slideShowService.addShow(show);
    }

    //上架图片
    @RequestMapping("grounding")
    private  void grounding(Integer slideshowId){
        slideShowService.grounding(slideshowId);
    }

    //下架图片
    @RequestMapping("undercarriage")
    private void undercarriage(Integer slideshowId){
        slideShowService.undercarriage(slideshowId);
    }

    //图片上传oss
    @RequestMapping("upload")
    public Object upload(MultipartFile imgfile, HttpServletRequest request) throws Exception{
        Map map = new HashMap();
        String upload2oss = OSSUtil.upload2oss(imgfile);
        map.put("url", upload2oss);
        return map;

    }

    //事件
    @RequestMapping("on")
    public Object on (Integer commodityId){
        return slideShowService.on(commodityId);
    }


}
